import shutil
from pathlib import Path
import os
import open3d as o3d
import numpy as np
import json
import math

def delete_empty_file(root_dir):
    root_dir = Path(root_dir)

    out_dir = root_dir
    out_lidar_dir = out_dir / 'training' / 'velodyne'
    out_calib_dir = out_dir / 'training' / 'calib'
    out_label_dir = out_dir / 'training' / 'label_2'
    out_set_dir = out_dir / 'ImageSets'

    for lf in out_label_dir.iterdir():
        with open(lf) as fset:
            if not os.path.getsize(lf):
                # print(lf.stem)
                lf.unlink()
                test_4 = out_calib_dir / f'{lf.stem}.txt'
                test_4.unlink()
                test_5 = out_lidar_dir / f'{lf.stem}.bin'
                test_5.unlink()

    with open(out_set_dir / 'train.txt', 'w') as fset:
        for lf in out_label_dir.iterdir():
            fset.write(f'{lf.stem}\n')

if __name__ == '__main__':
    out_dir = '../datasets/zw_0914_1102_1111/'
    delete_empty_file(out_dir)